﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.Collections;

namespace DrugStorehouseMIS.Comm
{
    public class ConvertDataType
    {
        public static string CheckFiledString(object obj)
        {
            try
            {
                if (obj != null && obj.ToString() != "")
                    return obj.ToString();
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
            return null;
        }

        public static int CheckFiledInt(object obj)
        {
            try
            {
                if (obj != null && obj.ToString() != "")
                    return Int32.Parse(obj.ToString());
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
            return 0;
        }

        public static DateTime CheckFiledDateTime(object obj)
        {
            try
            {
                if (obj != null && obj.ToString() != "")
                    return DateTime.Parse(obj.ToString());
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            
            }
            return DateTime.Now;
        }

        public static bool CheckFiledBool(object obj)
        {
            try
            {
                if (obj != null && obj.ToString() != "")
                    return obj.ToString() == "true" ? true : false;
            }
            catch (Exception ex)
            {

                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
            return false;
        }

        public static float CheckFieldFloat(object obj)
        {
            try
            {
                if (obj != null && obj.ToString() != "")
                    return float.Parse(obj.ToString());
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
            return 0;
        }
    }
}
